#!/bin/sh
[ "$1" = check ] || exit 1
LOCK=/var/lock/bypass.lock
LOG=/tmp/log/bypass.log
D="date +'%Y-%m-%d %H:%M:%S'"
# 防止重复启动
[ -f $LOCK ] && exit 1
touch $LOCK
sleep 2
while ! curl -so /dev/null -m 3 www.baidu.com;do
	sleep 2
done
echo "`eval $D` : Check network status successful!" >> $LOG
rm -f $LOCK
if [ ! -s /tmp/bypass/china.txt ] || ([ "$(uci -q get bypass.@global[0].run_mode)" = gfw -o "$(uci -q get bypass.@global[0].gfw_mode)" = 1 ] && [ ! -s /tmp/bypass/gfw.list ]);then
	echo "`eval $D` : Download IP/GFW files..." >> $LOG
	/usr/share/bypass/update --First &
else
	/etc/init.d/bypass start &
fi
